#coding=utf-8
from django import forms
from main import models
from django.forms.util import ErrorList
from DjangoUeditor.widgets import UEditorWidget
import datetime
import logging


logger = logging.getLogger('main')
class TemplateTextUpdateForm(forms.ModelForm):
    content = forms.CharField(label="内容",widget=UEditorWidget({"width":800, "height":600,"imagePath":'content/', "filePath":'filePath/',"toolbars":  [
                    ['fullscreen', 'source', 'undo', 'redo'],
                    ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset',
                      'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc','|',
                      'justifyleft', 'justifyright','justifycenter','justifyjustify','|','simpleupload','insertimage','imagecenter']]}))
    
    def __init__(self, *args, **kwargs):
        super(TemplateTextUpdateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.TemplateText
        fields = ['content']
    
    
class NewsRecordCreateForm(forms.ModelForm):
    content = forms.CharField(label="内容",widget=UEditorWidget({"width":800, "height":600,"imagePath":'content/', "filePath":'filePath/',"toolbars":  [
                    ['fullscreen', 'source', 'undo', 'redo'],
                    ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset',
                      'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc','|',
                      'justifyleft', 'justifyright','justifycenter','justifyjustify','|','simpleupload','insertimage','imagecenter']]}))
    
    def __init__(self, *args, **kwargs):
        super(NewsRecordCreateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.News
        fields = ['user_id','username','title','img','content','desc','sort']
    

class NewsRecordUpdateForm(forms.ModelForm):
    content = forms.CharField(label="内容",widget=UEditorWidget({"width":800, "height":600,"imagePath":'content/', "filePath":'filePath/',"toolbars":  [
                    ['fullscreen', 'source', 'undo', 'redo'],
                    ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset',
                      'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc','|',
                      'justifyleft', 'justifyright','justifycenter','justifyjustify','|','simpleupload','insertimage','imagecenter']]}))
    
    def __init__(self, *args, **kwargs):
        super(NewsRecordUpdateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.News
        fields = ['user_id','username','title','img','content','desc','sort']
    
class CoopertionRecordCreateForm(forms.ModelForm):
    
    def __init__(self, *args, **kwargs):
        super(CoopertionRecordCreateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.CoopertionPartner
        fields = ['user_id','username','name','img','href','desc','sort']
        
class CoopertionRecordUpdateForm(forms.ModelForm):
    
    def __init__(self, *args, **kwargs):
        super(CoopertionRecordUpdateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.CoopertionPartner
        fields = ['user_id','username','name','img','href','desc','sort']
        
        
class WebimgRecordUpdateForm(forms.ModelForm):
    
    def __init__(self, *args, **kwargs):
        super(WebimgRecordUpdateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.WebVisitImg
        fields = ['img']
    
         
class WebConfigCreateForm(forms.ModelForm):
    
    def __init__(self, *args, **kwargs):
        super(WebConfigCreateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.WebConfig
        fields = ['title']
        

class WebAdvImgUpdateForm(forms.ModelForm):
    
    def __init__(self, *args, **kwargs):
        super(WebAdvImgUpdateForm, self).__init__(*args, **kwargs)
        for field in self:
            field.field.widget.attrs['class'] = 'mws-textinput'

    class Meta:
        model = models.WebVisitImg
        fields = ['img']